<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 *个人信息维护
 */
if(0){?><script><?php }?>

    Ext.define('Hydcrm.user.UserPinfoWindow', {
        extend: 'Ext.Window',
        constructor: function(config) {  //alert("1111");
            config = config || {};
            
            config.id = 'user_pinfo_window';
            config.title = "个人信息维护";
            config.width = 500;
            config.iconCls = 'icon-pass';
            config.items = this.buildForm();

            config.buttons = [{
                    text: '关闭',
                    handler: function() {
                        this.close();
                    },
                    scope: this
                },{
                    text: '保存',
                    handler: function() {
                        this.submitForm();
                    },
                    scope: this
                }
            ];

            this.addEvents({'notifysuccess': true});
            this.addEvents({'savesuccess': true});
            
            this.frmUserPinfo.load({
                url: Hydcrm.CONF.CONN_URL,
                params: {
                    module: 'user',
                    controller: 'user_pinfo',
                    action: 'load_user_pinfo'
                },
                waitMsg : '正在载入...',
                success: function(form, action) { //alert(action.result.data.provinceid);//alert(form.getValues().provinceid);  

                },
                failure: function() {
                    Ext.Msg.alert('错误信息', '数据加载失败！');
                },
                scope: this
            });
            
            this.callParent([config]);
        },

        buildForm: function() {
            this.frmUserPinfo= Ext.create('Ext.form.FormPanel', {
                    url: Hydcrm.CONF.CONN_URL,
                    baseParams: {
                        module: 'user',
                        controller: 'user_pinfo',
                        action: 'edit_user_pinfo'
                    },
                    border: false,
                    bodyPadding: 10,
                    fieldDefaults: {
                        labelAlign: 'left',
                        labelWidth: 149,
                        msgTarget: 'side',
                        anchor: '98%'
                    },
                    items: [
                        {xtype: 'textfield', fieldLabel: 'ID', name: 'id', hidden: true, allowBlank: false},
                        {xtype: 'textfield', fieldLabel: '姓名', name: 'name', allowBlank: false},
                        {xtype: 'radiogroup',
                            fieldLabel: '性别',
                            defaults: {
                                name: 'sex'
                            },
                            items: [{
                                inputValue: 'M',
                                width: 100,
                                boxLabel: '女'
                            }, {
                                inputValue: 'F',
                                boxLabel: '男'
                            }]
                        },
                        {xtype: 'displayfield',name: 'tel',readOnly: true, fieldLabel: '手机号'},
                        
                        {xtype: 'displayfield',name: 'province_name',readOnly: true, fieldLabel: '所属省'},
                        {xtype: 'displayfield',name: 'city_name',readOnly: true, fieldLabel: '工作城市'},
                        {xtype: 'displayfield',name: 'team_name',readOnly: true, fieldLabel: '所属团队'},
                        {xtype: 'displayfield',name: 'department_name',readOnly: true, fieldLabel: '部门'},
                        {xtype: 'displayfield',name: 'position_name',readOnly: true, fieldLabel: '工作岗位'},
                        {xtype: 'displayfield',name: 'level_name',readOnly: true, fieldLabel: '角色'},
                        
                        {xtype: 'displayfield',name: 'worknum',readOnly: true, fieldLabel: '工号'},
                        {xtype: 'displayfield',name: 'entrytime',readOnly: true,fieldLabel: '入职时间'}
                        
                    ]
                });
            return this.frmUserPinfo;
        },

        submitForm: function() {
            this.frmUserPinfo.form.submit({
                waitMsg: '正在提交请稍候',
                success: function(form, action) { //this.fireEvent('savesuccess', action.result.feedback);
                    Ext.Msg.alert("提示信息", action.result.feedback);
                    this.close();
                    //window.location = 'index.php/login/loginout';
                },
                failure: function(form, action) {
                    if (action.failureType != 'client') {
                        //Ext.Msg.alert("错误", action.result.feedback);
                    }
                },
                scope: this
            });
        }

    });